package com.niuke;

import java.util.Scanner;

/**
 * 40. 字符串比较
 * https://blog.csdn.net/m0_46181452/article/details/131666890
 */
public class NiukeMoni40 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        int max = Integer.parseInt(scanner.nextLine());

        int res = 0; // 记录符合条件结果的长度
        if (str1.length() == str2.length()) { // 必要条件
            int next = 0;
            int currSum = 0;

            out:
            for (int i = 0; i < str1.length(); i++) {
                if (next < i) {
                    next = i;
                }
                for (int j = next; j < str1.length(); j++) {
                    int diff = Math.abs(str1.charAt(next) - str2.charAt(next));
                    currSum += diff;

                    // 如果最后一个位置也符合条件，得到结果并break掉整个循环
                    if (j == str1.length() - 1 && currSum <= max) {
                        res = Math.max(res, j - i + 1);
                        break out;
                    }

                    if (currSum > max) {
                        res = Math.max(res, j - i);
                        if (j == i) {
                            currSum = 0;
                        } else {
                            currSum = currSum - Math.abs(str1.charAt(i) - str2.charAt(i)) - diff;
                        }
                        next = j;
                        break; // break 里面这个循环
                    }
                }
            }

            System.out.println(res);
        }

    }

}
